package com.yn.xgame.message;

import com.yn.xgame.IMessage;
import com.yn.xgame.pb.ClientAccessProto;
import com.yn.xgame.pb.MessageIdProto;
import io.netty.channel.ChannelHandlerContext;

/**
 * Client - Access protobuf 请求消息
 * Created by wangboo on 2017/7/12.
 */
public class C2APbMessage implements IMessage {

    private ClientAccessProto.C2AMessage pb;
    private ChannelHandlerContext ctx;

    public C2APbMessage(ChannelHandlerContext ctx, ClientAccessProto.C2AMessage pb) {
        this.ctx = ctx;
        this.pb = pb;
    }

    public ClientAccessProto.C2AMessage getProto() {
        return pb;
    }

    public MessageIdProto.MessageId getMsgId() {
        return pb.getMsgid();
    }

    public void sendAndClose(ClientAccessProto.A2CMessage resp) {
        ctx.writeAndFlush(resp).addListener((_void)-> ctx.close());
    }

}
